Add methods allowing masking of Strings#332
Conversation
maskStart and maskEnd allow masking the original str by replacing it's characters with the specified character-mask. Common usecase is to hide sensitive information from logs, by using it in toString of classes or in inputs to log calls.
|
Hi @greenman18523 thank for your contribution - from my experience this is "must have" functionality for Commons Lang library because in almost all bit projects what I saw was their home grown masking function. But what I would like to propose is to simplify the api and use one function Please give your feedback, |
|
Hello @stokito, thanks for the input. The reasoning of creating two method was for a more intuitive API and to not add too many parameters in just one method. And I also didn't want to create a 3rd method that would just do the main logic without it being able to be exposed (i.e. private). I like the idea of the mask being in the middle of the string, and I was thinking of incorporating it into the code, but was not sure how useful it would be for others. An other goal of the way the methods are, is to clearly enforce a minimum amount of masking before being able to show any information. e.g. in the case of a credit card, even if the user has erroneously entered 8 out of the 16 characters, a call to I think that both implementations can be useful for a number of use-cases, some common to both, but some are covered by one of the two implementation. Of course this can also be achieved by an extra parameter in your implementation. What do you think? |
maskStart and maskEnd now call the new method Also Arrays.fill is now used, in place of the for loop, to take advantage of possible intrinsics by the JVM http://mail.openjdk.java.net/pipermail/hotspot-compiler-dev/2014-February/013294.html
|
New method added, to cover usacases of https://issues.apache.org/jira/browse/LANG-1400 |
Well, and I had to add another one to address NUTCH-2905 in apache/nutch#704. We had one additional use case: mask only a part of string matched by a regular expression. |
|
Masking might belong in Commons Text, not here in Commons Lang IMO. |
|
As a basic secure functionality it must be in core Java library or better even as a method of |
There is no point arguing here what belongs in what JRE class ;-) |
|
Closing: No action in 3 years. See reference to Commons Text. Also Java has stock support for replace methods and regular expressions. |
maskStart and maskEnd allow masking the original str by replacing it's
characters with the specified character-mask.
Common usecase is to hide sensitive information from logs, by using it
in toString of classes or in inputs to log calls.